//
//  SEGSignSuccessView.m
//  SEGUhomePropertyBaseService
//
//  Created by Clavis on 2018/10/18.
//  Copyright © 2018 刘山. All rights reserved.
//

#import "SEGSignSuccessView.h"

@implementation SEGSignSuccessView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = kColor_W;
    UIImageView *successIcon = ({
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_success")];
        [self addSubview:imageView];
        imageView;
    });
    
    UILabel *tipLabel = ({
        UILabel *lable = [[UILabel alloc] init];
        lable.font = kFont_17;
        lable.textColor = kColor_1;
        lable.text = @"签字成功";
        [self addSubview:lable];
        lable;
    });
    self.tipLabel = tipLabel;
    
    UIButton *backHomeButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"返回首页" forState:UIControlStateNormal];
        [button setTitleColor:kColor_1 forState:UIControlStateNormal];
        [button addTarget:self action:@selector(backHomeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.layer.borderWidth = 1;
        button.layer.borderColor = kColor_C.CGColor;
        button.layer.cornerRadius = 4;
        button.layer.masksToBounds = YES;
        button.titleLabel.font = kFont_17;
        [self addSubview:button];
        button;
    });
    
    UIButton *backOrderDetailButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"查看详情" forState:UIControlStateNormal];
        [button setTitleColor:kColor_W forState:UIControlStateNormal];
        [button addTarget:self action:@selector(backOrderDetailButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.backgroundColor = kColor_T;
        [button setBackgroundImage:[UIImage imageWithColor:kColor_T] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageWithColor:kColor_T_Press] forState:UIControlStateHighlighted];
        button.layer.cornerRadius = 4;
        button.titleLabel.font = kFont_17;
        [self addSubview:button];
        button;
    });
    
    [backOrderDetailButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(270);
        make.height.mas_equalTo(44);
    }];
    
    [backHomeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerX.equalTo(backOrderDetailButton);
        make.bottom.equalTo(backOrderDetailButton.mas_top).offset(-10);
    }];
    
    [successIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.mas_equalTo((LYScreenHeight()/2.0 - 76)/2.0 - 25);
    }];
    
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(successIcon.mas_bottom).offset(12);
    }];
}

- (void)backHomeButtonClick:(UIButton *)sender {
    if (self.backHomeBlock) {
        self.backHomeBlock();
    }
    [self removeFromSuperview];
}

- (void)backOrderDetailButtonClick:(UIButton *)sender {
    if (self.backOrderDetailBlock) {
        self.backOrderDetailBlock();
    }
    [self removeFromSuperview];
}

@end
